import request from "@/utils/request";
import { AllBudgetQuery, BOMQuery, BomVo } from "@/api/forecast/types";
import axios from "axios";

/**
 * 物料BOM树获取
 */
export function getBOMTree(params: BOMQuery) {
  return request({
    url: "/api/v1/forecast/tree",
    method: "get",
    params: params,
  });
}

/**
 * 物料BOM计算
 */
export function getBOMCalculate(params: BOMQuery) {
  return request({
    url: "/api/v1/forecast/calculate",
    method: "get",
    params: params,
  });
}

/** 全面预算,批量出表格 **/
export async function allBudget(data: any) {
  return request({
    url: "/api/v1/forecast/allBudget",
    method: "post",
    data: data,
    responseType: "arraybuffer", // 设置响应类型为arraybuffer，用于接收二进制文件流
  });
}

/**
 * 物料BOM计算
 */
export function getBOMErr(query: any) {
  return request({
    url: "/api/v1/forecast/err",
    method: "get",
    params: query,
  });
}

/**
 * 更新BOM
 */
export function editBOM(data: BomVo) {
  return request({
    url: "/api/v1/forecast",
    method: "put",
    data: data,
  });
}

export function getBOMOne(itemMaster: string) {
  return request({
    url: "/api/v1/forecast",
    method: "get",
    params: { itemMaster: itemMaster },
  });
}

export function getConfig(name: string) {
  return request({
    url: "/api/v1/forecast/config",
    method: "get",
    params: { name: name },
  });
}

export function updateConfig(name: string, data: {}) {
  return request({
    url: "/api/v1/forecast/config",
    method: "put",
    data: { name: name, data: JSON.stringify(data) },
  });
}

export function rmCache(data: any) {
  return request({
    url: "/api/v1/forecast/cache",
    method: "delete",
    data: data,
  });
}

export function addCache(key: { key: string }, data: any) {
  return request({
    url: "/api/v1/forecast/cache",
    method: "put",
    params: key,
    data: data,
  });
}
